package com.github.data_manage

import com.github.data_manage.controller.FundController
import com.github.data_manage.dao.FundDao
import com.github.data_manage.domain.vo.FundPageParam
import com.github.data_manage.domain.vo.NumberRangeQuery
import com.github.data_manage.enum.NumberRelation
import com.github.data_manage.util.consumeAsyncBlocking
import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.mock.web.MockMultipartFile
import java.math.BigDecimal
import java.nio.file.Files
import java.nio.file.Paths
import kotlin.time.measureTime


/**
 *@author CHN
 *@since 2024-08-10 17:05
 */
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class FundDaoTests {

    @Autowired
    lateinit var fundDao: FundDao

    @Autowired
    lateinit var fundController: FundController

    companion object{
        private val log: Logger = LoggerFactory.getLogger(FundDaoTests::class.java)

    }

    @Test
    fun tests(){
        val fundPageParam = FundPageParam()
        fundPageParam.pageNum = 1
        fundPageParam.pageSize = 10
        fundPageParam.corePerson = "123124"
        val numberRangeQuery = NumberRangeQuery()
        numberRangeQuery.relation = NumberRelation.EQ
        numberRangeQuery.value = BigDecimal.valueOf(1)
        fundPageParam.aum = numberRangeQuery
        fundDao.countFund(fundPageParam)
    }

    @Test
    fun fundDataImportTest(){
        Files.newInputStream(Paths.get("/Users/chenhainan/Downloads/基金数据导入-测试.xlsx")).use {fis ->
            val mockMultipartFile = MockMultipartFile("excelFile",fis)
            val time = measureTime {
                fundController.importFundBusinessDataNew(mockMultipartFile,"1234")
            }
            println(time)
        }
        Thread.sleep(10 * 60 * 1000L)
    }

    @Test
    fun fundImportTest(){
        Files.newInputStream(Paths.get("C:\\Users\\18066\\Downloads\\基金导入.xlsx")).use {fis ->
            val mockMultipartFile = MockMultipartFile("excelFile",fis)
            val time = measureTime {
                fundController.importBaseTemplate(mockMultipartFile)
            }
            println(time)
        }

    }

    @Test
    fun fundYearDataTest(){
//        for (fund in fundDao.findAll()) {
//            val (yearNav, yearStandardDeviation) = fundController.fundYearInfo(fund.fundId!!)
//            fund.yearNav = yearNav
//            fund.yearStandardDeviation = yearStandardDeviation
//            fundDao.save(fund)
//        }
    }

    @Test
    fun fundCalcTest(){

    }

}
